#include<string>
#include<vector>
#include<array>
#include<unordered_map>
#include<algorithm>
#include<limits>
#include <stack>
#include <iostream>
#define MOD 1000000007
class Solution {
public:
    int largestRectangleArea(std::vector<int>& heights) {
        std::stack<int> istack;
        int n = heights.size();
        int ans=0;
        for (int i = 0; i < n; i++)
        {
            if (istack.empty()||heights[istack.top()]<=heights[i])
            {
                istack.push(i);
                continue;
            }
            while (!istack.empty() && heights[istack.top()]>heights[i])
            {
                int index = istack.top();
                istack.pop();
                int r= i;
                int l = istack.empty()?-1:istack.top();
                ans = std::max((r-l-1)*heights[index],ans);
            }
            istack.push(i);
        }
        while (!istack.empty())
        {
            int index = istack.top();
            istack.pop();
            int r= n;
            int l = istack.empty()?-1:istack.top();
            ans = std::max((r-l-1)*heights[index],ans);
        }
        return ans;
    }
    int maximalRectangle(std::vector<std::vector<char>>& matrix) {
        int n = matrix.size();
        int m = matrix[0].size();
        std::vector<int> last (m,0);
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                last[j]=matrix[i][j]=='0'?0:last[j]+matrix[i][j]-'0';
         
            }
            std::cout << std::endl;
            ans = std::max(ans,largestRectangleArea(last));
        }
        return ans;
    }
};
